package cuiyt.algorithm.dfs;

import algorithm.TreeNode;

/**
 * @author cyt
 * @create 2020-09-03 20:50
 */
public class T129 {
    public static void main(String[] args) {

    }


    public int sumNumbers(TreeNode root) {
        return dfs(root, 0);
    }

    public int dfs(TreeNode root, int val) {
        if (root == null) {
            return 0;
        }
        int ans = val * 10 + root.val;
        if (root.left == null && root.right == null) {
            return ans;
        }
        return dfs(root.right, ans) + dfs(root.left, ans);
    }

}
